#!/bin/sh

# script to start a Streambake session
# script is meant to be run from inittab

# FIXME
# rework this so it's called from menu.sh;
# - have menu start/stop the streaming script
# - have menu rescan the drives for changes
# - allow changing for the stream title
# - report on the total number of files found across all media

# source ant_functions for colorization
source /etc/ant_functions.sh

MP3_FILELIST="/tmp/foundlist.m3u"
export ICECAST_SOURCE_PASS="stoleju"

MP3_COUNT=$(wc -l ${MP3_FILELIST} | awk '{print $1}' | tr -d '\n')
echo
colorize_nl $S_FAILURE "+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+"
colorize_nl $S_FAILURE "+      PROPAGANDA STREAMING AUDIO SERVER      +"
colorize_nl $S_FAILURE "+  http://code.google.com/p/propaganda-audio  +"
colorize_nl $S_FAILURE "+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+"
echo "You can log in and/or interact with the system by switching "
echo "virtual consoles;"
echo
echo "==VC==    ==VC Purpose=="
echo "Alt-F1    Propaganda Menu - Control the running system"
echo "Alt-F2    This information message + streaming script output" 
echo "Alt-F3    Login shell (login info printed in banner)"
echo "Alt-F4    Login shell (login info printed in banner)"
echo "Alt-F5    Login shell (login info printed in banner)"
echo
echo "This virtual console will only display the output"
echo "of the streaming script, you cannot log in on this console"
echo
echo "Current IP addresses are:"
/sbin/ifconfig | grep "inet addr"
echo "To listen to this stream, enter the following URL into your favorite"
echo "MP3 player: 'http://<my IP address>:8000/propaganda'"
echo "The system has cataloged ${MP3_COUNT} files for streaming"

# test to see that the filelist file is not empty
if [ -s $MP3_FILELIST ]; then
    /usr/bin/perl /bin/simplebake.pl < $MP3_FILELIST 2>/var/log/simplebake.log
    exit 0
else 
    echo "Hmmm...."
    echo "File '${MP3_FILELIST}' exists but is zero bytes in size"
    echo "This is confusing, so I will do nothing and exit"
fi

echo "Sleeping 60 seconds"
echo "(in case something went wrong trying to start the demo)"
sleep 60
exit 1
